package de.fmannan.wildit.service;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AlarmSetter {

	
	public static void scheduleAlarm(Context context, Calendar start, Calendar end, Calendar interval)
	{
		Toast.makeText(context, "Scheduling Alarm", Toast.LENGTH_LONG).show();		
		
		PendingIntent intent = PendingIntent.getBroadcast(context, 100,
				new Intent(context, AlarmReceiver.class), 0);
		
		AlarmManager manager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
		//Schedule alarm
		manager.setRepeating(AlarmManager.RTC_WAKEUP, System
				.currentTimeMillis(), timeToMilliseconds(interval
				.get(Calendar.HOUR_OF_DAY), interval.get(Calendar.MINUTE)),
				intent);		
		//Persist alarm
	}
	
	private static long timeToMilliseconds(int hourOfTheDay, int minutes)
	{
		return (hourOfTheDay * 60 + minutes) * 60000;
		
	}
	
}
